package com.android.lovepick;

import java.util.List;

import android.app.ActionBar;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;

import com.android.lovepick.util.BaseUtils;
import com.android.lovepick.util.ChatMsg;
import com.android.lovepick.util.ChatMsgAdapter;

public class ChatMsgActivity extends Activity
{
	private final String CHATMSG_TAG = "ChatMsgActivity";
	private TextView txvDate;
	private EditText edtMsgContent;
	private Button btnSend;
	private ListView lvMsgList;

	private List<ChatMsg> mChatMsgs = null;
	private ChatMsgAdapter mAdapter = null;

	@SuppressWarnings("unchecked")
	@Override
	public void onCreate(Bundle bundle)
	{
		super.onCreate(bundle);
		setContentView(R.layout.chatmsg);
		getWindow().setSoftInputMode(
				WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
		findViews();
		String nickName = this.getIntent().getStringExtra("nickname");
		mChatMsgs = (List<ChatMsg>) this.getIntent().getSerializableExtra(
				"chatmsgs");
		mAdapter = new ChatMsgAdapter(this, mChatMsgs);
		lvMsgList.setAdapter(mAdapter);
		ActionBar actionBar = getActionBar();
		actionBar.setTitle(nickName);
	}

	private void findViews()
	{
		txvDate = (TextView) this.findViewById(R.id.txv_date);
		edtMsgContent = (EditText) this.findViewById(R.id.edt_msgcontent_chat);
		btnSend = (Button) this.findViewById(R.id.btn_send_chat);
		lvMsgList = (ListView) this.findViewById(R.id.lv_msglist_chat);
	}

	public void sendMsg(View v)
	{
		String currentDate = BaseUtils.getCurrentDate();
		txvDate.setText(currentDate);
		String content = edtMsgContent.getText().toString();
		ChatMsg chatMsg = new ChatMsg();
		chatMsg.setContent(content);
		chatMsg.setDate(currentDate);
		chatMsg.setSendOrRcv(false);
		mChatMsgs.add(chatMsg);
		mAdapter.notifyDataSetChanged();

	}

}
